2020-2021 Sunseeker Telemetry and Lighting System
icc_ex1_nestedInterrupt.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
74 //******************************************************************************
75 #include "driverlib.h"
76 #include "Board.h"
77 
78 void main (void)
79 {
80  //Stop Watchdog Timer
81  WDT_A_hold(WDT_A_BASE);
82 
83  //Set MCLK output (optional for debugging)
84  GPIO_setAsPeripheralModuleFunctionOutputPin(
85  GPIO_PORT_MCLK,
86  GPIO_PIN_MCLK,
87  GPIO_FUNCTION_MCLK);
88  //REFO sources MCLK
89  CS_initClockSignal(
90  CS_MCLK,
91  CS_REFOCLK_SELECT,
92  CS_CLOCK_DIVIDER_1);
93  //Clear all OSC fault flags
94  CS_clearAllOscFlagsWithTimeout(1000);
95 
96  //Set S1 and S2 as input pins pulled-up.
97  GPIO_setAsInputPinWithPullUpResistor(
98  GPIO_PORT_S1 | GPIO_PORT_S2,
99  GPIO_PIN_S1 | GPIO_PIN_S2);
100 
101  //Set LED1 and LED2 as output pins.
102  //Clear LED1 and LED2 output latch for a defined power-on state
104  GPIO_PORT_LED1 | GPIO_PORT_LED2,
105  GPIO_PIN_LED1 | GPIO_PIN_LED2);
106  GPIO_setAsOutputPin(
107  GPIO_PORT_LED1 | GPIO_PORT_LED2,
108  GPIO_PIN_LED1 | GPIO_PIN_LED2);
109 
110  /*
111  * S1 and S2
112  * Set hi/low edge
113  * Interrupt enable
114  */
115  GPIO_selectInterruptEdge(
116  GPIO_PORT_S1 | GPIO_PORT_S2,
117  GPIO_PIN_S1 | GPIO_PIN_S2,
118  GPIO_HIGH_TO_LOW_TRANSITION);
119  GPIO_enableInterrupt(
120  GPIO_PORT_S1 | GPIO_PORT_S2,
121  GPIO_PIN_S1 | GPIO_PIN_S2);
122 
123  /*
124  * Disable the GPIO power-on default high-impedance mode to activate
125  * previously configured port settings
126  */
127  PMM_unlockLPM5();
128 
129  /*
130  * Clear S1 and S2 flag
131  */
132  GPIO_clearInterrupt(
133  GPIO_PORT_S1 | GPIO_PORT_S2,
134  GPIO_PIN_S1 | GPIO_PIN_S2);
135 
136  /*
137  * Initialize RTC
138  * RTC count reload compare value at 256.
139  * 1024/32768 * 256 = 8 seconds
140  * Source = 32kHz crystal, divided by 1024
141  */
142  RTC_init(
143  RTC_BASE,
144  256-1,
145  RTC_CLOCKPREDIVIDER_1024);
146  RTC_enableInterrupt(
147  RTC_BASE,
148  RTC_OVERFLOW_INTERRUPT);
149  RTC_start(
150  RTC_BASE,
151  RTC_CLOCKSOURCE_XT1CLK);
152 
153  /*
154  * Initialize and enable ICC
155  */
156  //Disable global interupt during setup
157  __bic_SR_register(GIE);
158 
159  //NOTE: ICC_LEVEL_0 is the highest priority, ICC_LEVEL3 is the lowest priority
160  //Set P4 interrupt highest priority
161  ICC_setInterruptLevel(ICC_ILSR_P4, ICC_LEVEL_0);
162  //Set P2 interrupt lowest priority
163  ICC_setInterruptLevel(ICC_ILSR_P2, ICC_LEVEL_3);
164  //Set RTC interrupt medium priority
165  ICC_setInterruptLevel(ICC_ILSR_RTC_COUNTER, ICC_LEVEL_1);
166 
167  //Enable ICC module
168  ICC_enable();
169 
170  //Enter LPM3 and global interrupt
171  __bis_SR_register(LPM3_bits + GIE);
172 }
173 
174 // Port 4 interrupt service routine
175 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
176 #pragma vector=PORT4_VECTOR
177 __interrupt void Port_4(void)
178 #elif defined(__GNUC__)
179 void __attribute__ ((interrupt(PORT4_VECTOR))) Port_4 (void)
180 #else
181 #error Compiler not supported!
182 #endif
183 {
184  //Clear S1 IFG
185  GPIO_clearInterrupt(
186  GPIO_PORT_S1,
187  GPIO_PIN_S1);
188  //Set LED1 and LED2 to indicate port interrupt
190  GPIO_PORT_LED1 | GPIO_PORT_LED2,
191  GPIO_PIN_LED1 | GPIO_PIN_LED2);
192  // Keep LED1 and LED2 output high for 0.5 second
193  __delay_cycles(500000);
194  //Clear LED1 and LED2 output
196  GPIO_PORT_LED1 | GPIO_PORT_LED2,
197  GPIO_PIN_LED1 | GPIO_PIN_LED2);
198 }
199 
200 // Port 2 interrupt service routine
201 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
202 #pragma vector=PORT2_VECTOR
203 __interrupt void Port_2(void)
204 #elif defined(__GNUC__)
205 void __attribute__ ((interrupt(PORT2_VECTOR))) Port_2 (void)
206 #else
207 #error Compiler not supported!
208 #endif
209 {
210  //Clear S2 IFG
211  GPIO_clearInterrupt(
212  GPIO_PORT_S2,
213  GPIO_PIN_S2);
214  //Set LED2 to indicate port interrupt
216  GPIO_PORT_LED2,
217  GPIO_PIN_LED2);
218  // Keep LED2 output high for 0.5 second
219  __delay_cycles(500000);
220  //Clear LED2 output
222  GPIO_PORT_LED2,
223  GPIO_PIN_LED2);
224 }
225 
226 // RTC interrupt service routine
227 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
228 #pragma vector=RTC_VECTOR
229 __interrupt void RTC_ISR(void)
230 #elif defined(__GNUC__)
231 void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void)
232 #else
233 #error Compiler not supported!
234 #endif
235 {
236  switch(__even_in_range(RTCIV,RTCIV_RTCIF))
237  {
238  case RTCIV_NONE: break; // No interrupt
239  case RTCIV_RTCIF: // RTC Overflow
240  //Enable global interrupt
241  __bis_SR_register(GIE);
242  //Set LED1 to indicate RTC interrupt
244  GPIO_PORT_LED1,
245  GPIO_PIN_LED1);
246  //Keep LED1 output high for 4 seconds
247  __delay_cycles(4000000);
248  //Clear LED1 output
250  GPIO_PORT_LED1,
251  GPIO_PIN_LED1);
252  break;
253  default: break;
254  }
255 }
256 
void RTC_ISR(void)
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
void main(void)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)